#!/usr/bin/python3

import os
import logging
import logging.handlers
import xml.etree.cElementTree as cET

from dbPool import *



def initXmlAndMysqlParam(dbConnPool, log):
    serviceHost = "0.0.0.0"
    servicePort = 8888
    xmlFile = "../conf/config.xml"
    xmlFilePath = os.path.abspath(xmlFile)
    try:
        tree = cET.parse(xmlFilePath)
        root = tree.getroot()
        # g_log.log(str(tree), logging.INFO)

        dbConf = root.find("db_conf")
        dbConnPool[0]=CDBConnPool(log, connCount=3,
                                 dbHost=dbConf.get("host"),
                                 dbPort=int(dbConf.get("port")),
                                 dbUser=dbConf.get("user"),
                                 dbPwd=dbConf.get("pwd"),
                                 dbName=dbConf.get("db_name")
                                 )

        webConf = root.find("web_src_conf")
        serviceHost = webConf.get("host")
        servicePort = webConf.get("port")

        return (serviceHost, servicePort)

    except Exception as e:  # 捕获除与程序退出sys.exit()相关之外的所有异常
        log.log("failed when parse xml !", logging.ERROR)



